﻿// -----------------------------------------------------------------------
// <copyright file="Win32API.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace SubtitleFontCollector
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;

    /// <summary>
    /// Including all win32 API.
    /// </summary>
    public class Win32API
    {
        private const int LocaleSystemDefault = 0x0800;
        private const int LcmapSimplifiedChinese = 0x02000000;
        private const int LcmapTraditionalChinese = 0x04000000;

        [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern int LCMapString(int locale, int dwMapFlags, string lpSrcStr, int cchSrc, [Out] string lpDestStr, int cchDest);

        /// <summary>
        /// convert Traditional Chinese character to simplified Chinese character.
        /// </summary>
        /// <param name="argSource">the string will be converted.</param>
        /// <returns>simplified Chinese character</returns>
        public static string ToSimplified(string argSource)
        {
            var t = new string(' ', argSource.Length);
            LCMapString(LocaleSystemDefault, LcmapSimplifiedChinese, argSource, argSource.Length, t, argSource.Length);
            return t;
        }

        /// <summary>
        /// convert simplified Chinese character to Traditional Chinese character.
        /// </summary>
        /// <param name="argSource">the string will be converted.</param>
        /// <returns>Traditional Chinese character</returns>
        public static string ToTraditional(string argSource)
        {
            var t = new string(' ', argSource.Length);
            LCMapString(LocaleSystemDefault, LcmapTraditionalChinese, argSource, argSource.Length, t, argSource.Length);
            return t;
        }
    }
}
